package com.webchat.ugc.controller;

import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.SendRedPacketRequestVO;
import com.webchat.rmi.ugc.RedPacketClient;
import com.webchat.ugc.service.redpacket.RedPacketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedPacketController implements RedPacketClient {

    @Autowired
    private RedPacketService redPacketService;

    @Override
    public APIResponseBean<Long> send(@RequestBody SendRedPacketRequestVO sendRedPacketRequest) {

        Long redPacketId = redPacketService.send(sendRedPacketRequest);
        return APIResponseBeanUtil.success(redPacketId);
    }

    @Override
    public APIResponseBean<String> open(@PathVariable Long redPacketId, @PathVariable String userId) {

        // 红包金额避免精度等引发的展示数据不准确问题，一般返回给VIEW层使用String类型较多
        String money = redPacketService.open(redPacketId, userId);
        return APIResponseBeanUtil.success(money);
    }
}
